//
//  StoreDetailBottomView.m
//  BaseProject
//
//  Created by 王洋 on 2020/7/2.
//  Copyright © 2020 王洋. All rights reserved.
//

#import "StoreDetailBottomView.h"

@interface StoreDetailBottomView ()

@end

@implementation StoreDetailBottomView

- (void)awakeFromNib {
    [super awakeFromNib];
    
    [self.imControl addGestureTapEventHandle:^(id  _Nonnull sender, UITapGestureRecognizer * _Nonnull gestureRecognizer) {
        if (self.StoreDetailBottomBlock) {
            self.StoreDetailBottomBlock(StoreDetailBottomActionType_im);
        }
    }];
    
    [self.phoneControl addGestureTapEventHandle:^(id  _Nonnull sender, UITapGestureRecognizer * _Nonnull gestureRecognizer) {
        if (self.StoreDetailBottomBlock) {
            self.StoreDetailBottomBlock(StoreDetailBottomActionType_phone);
        }
    }];
    
    [self.evaluateControl addGestureTapEventHandle:^(id  _Nonnull sender, UITapGestureRecognizer * _Nonnull gestureRecognizer) {
        if (self.StoreDetailBottomBlock) {
            self.StoreDetailBottomBlock(StoreDetailBottomActionType_evaluate);
        }
    }];
}

- (void)layoutSubviews {
    [super layoutSubviews];
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [self.handleBtn pp_clipCorners:UIRectCornerAllCorners radius:self.handleBtn.frame.size.height/2];
        [self.scheduleBtn pp_clipCorners:UIRectCornerAllCorners radius:self.scheduleBtn.frame.size.height/2 border:1 color:UIColorHex(0xff4242)];
    });
    self.phoneControl.hidden = YES;
}

- (void)refreshWithType:(StoreDetailBottomUIType)type {
    
    switch (type) {
        case StoreDetailBottomUIType_schedule:{
            self.handleBtnW.constant = (TTScreenWidth - 120 - 20 - 60)/2;
            self.scheduleBtnW.constant = (TTScreenWidth - 120 - 20 - 60)/2;
        } break;
        case StoreDetailBottomUIType_subscribe:{
            self.handleBtnW.constant = (TTScreenWidth - 120 - 20 - 40);
            self.scheduleBtn.hidden = YES;
        } break;
        default:
            break;
    }


}

- (IBAction)handleAction:(id)sender {
    if (self.StoreDetailBottomBlock) {
        self.StoreDetailBottomBlock(StoreDetailBottomActionType_handle);
    }
}

- (IBAction)scheduleAction:(id)sender {
    if (self.StoreDetailBottomBlock) {
        self.StoreDetailBottomBlock(StoreDetailBottomActionType_schedule);
    }
}

@end
